package com.asiainfo.demo.dao.dbcon;

import java.io.FileInputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.util.Enumeration;
import java.util.Properties;

public class IYogaCon {
    private Connection con = null;
//    private static final String DRIVER = "com.mysql.jdbc.Driver";
//    private static final String USER = "root";
//    private static final String URL = "jdbc:mysql://120.26.128.45:3306/iyogo?characterEncoding=UTF-8";
//    private static final String PASS = "root1234";

    public IYogaCon() throws Exception {
        Properties properties = new Properties();
        properties.load(new FileInputStream("db.properties"));

        final String DRIVER = properties.getProperty("DRIVER");
        final String USER = properties.getProperty("USER");
        final String URL = properties.getProperty("URL");
        final String PASS = properties.getProperty("PASS");

        Class.forName(DRIVER);
        con = DriverManager.getConnection(URL, USER, PASS);
    }

    public Connection getConnection() throws Exception {
        return con;
    }

    public void close() throws Exception {
        if (con != null) {
            con.close();
        }
    }
}
